package main

import (
	"context"
	"demo-grpc/pb"
	"fmt"
	"log"
	"net"

	"google.golang.org/grpc"
)

type UserInfoService struct {
}

var u = UserInfoService{}

func (s *UserInfoService) GetUserInfo(ctx context.Context, req *pb.UserRequest) (resp *pb.UserResponse, err error) {
	name := req.Name
	resp = &pb.UserResponse{
		Name: fmt.Sprintf("UserReq %v ", name),
	}
	err = nil
	return
}

func (s *UserInfoService) GetTaskInfo(ctx context.Context, req *pb.TaskRequest) (resp *pb.UserResponse, err error) {
	name := req.Name
	resp = &pb.UserResponse{
		Name: fmt.Sprintf("TaskReq %v ", name),
	}
	err = nil
	return
}

func main() {
	addr := "127.0.0.1:8080"
	lis, err := net.Listen("tcp", addr)
	if err != nil {
		log.Fatalf("failed to listen: %v", err)
	}

	s := grpc.NewServer()

	// b = pb.ProtoServiceServer{}
	pb.RegisterUserInfoServiceServer(s, &u)
	s.Serve(lis)
}
